package cubelabs.nexus.dao;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import cubelabs.nexus.entity.User;
import cubelabs.nexus.entity.UserCategory;

@Repository("userCategoryDAO")
public class UserCategoryDAO extends BaseDAO<UserCategory, Long>{

	public UserCategory findByCategoryAndUser(Long categoryId, Long userId){
		Criteria crit = getSession().createCriteria(getPersistentClass());
		crit.add(Restrictions.and(Restrictions.eq("category.id", categoryId),Restrictions.eq("user.id", userId)));
		UserCategory userCategory  = (UserCategory) crit.uniqueResult();
		return userCategory;
	}
	
}
